package com.core.zyyz.amc.modules.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.ValueSetValue;
import com.core.zyyz.pcmc.service.ValueSetValueService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.zyyz.amc.modules.domain.AmcCusBaseInfoB;
import com.core.zyyz.amc.modules.service.AmcCusBaseInfoBService;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 客户基本信息Controller
 *
 * @author lfs
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/amc/cusmanager")
public class AmcCusBaseInfoBController extends BaseController
{
    @Autowired
    private AmcCusBaseInfoBService amcCusBaseInfoBService;
    @Autowired
    private ValueSetValueService valueSetValueService;

    /**
     * 查询客户基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('amc:cusmanager:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmcCusBaseInfoB amcCusBaseInfoB)
    {
        startPage();
        List<AmcCusBaseInfoB> list = amcCusBaseInfoBService.selectAmcCusBaseInfoBList(amcCusBaseInfoB);
        return getDataTable(list);
    }

    /**
     * 导出客户基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('amc:cusmanager:export')")
    @Log(title = "客户基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AmcCusBaseInfoB amcCusBaseInfoB)
    {
        List<AmcCusBaseInfoB> list = amcCusBaseInfoBService.selectAmcCusBaseInfoBList(amcCusBaseInfoB);
        ExcelUtil<AmcCusBaseInfoB> util = new ExcelUtil<AmcCusBaseInfoB>(AmcCusBaseInfoB.class);
        util.exportExcel(response, list, "客户基本信息数据");
    }

    /**
     * 获取客户基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('amc:cusmanager:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") String customerId)
    {
        return success(amcCusBaseInfoBService.selectAmcCusBaseInfoBByCustomerId(customerId));
    }


    /**
     * 查询客户类型cus_type具体的集值数据（客户类型中下拉框的值）
     * @return
     */
    @GetMapping("/valueSetCusList")
    public AjaxResult valueSetCusList(){
        Map<String, Object> map = new HashMap<String, Object>();
       //从集值详情表中查询具体的值 value_set_value
        ValueSetValue value = new ValueSetValue();
        value.setValueSetCode("cus_type");
        List<ValueSetValue> valueSetValues = valueSetValueService.selectValueSetValueList(value);
        map.put("cus_type", valueSetValues);
        return success(map);
    }

    /**
     * 根据选择的客户类型cus_type去查询具体的集值数据（页面中下拉框的值）
     * 01代表企业客户  02代表个人客户
     * @param valueSetCode
     * @return
     */
    @GetMapping("/valueSetCodeList")
    public AjaxResult valueSetCodeList(@RequestParam String valueSetCode){
        Map<String, Object> map = new HashMap<String, Object>();
        String[] str;
        if ("01".equals(valueSetCode)){
            //enterprise_scale 企业规模;counterparty_type交易对手类型;economic_type经济类型;listed_compary_yes_no上市标志;sup_org_type上级机构类型;actual_controller_type控股人类型;certificate_type证件类型
             str = new String[]{"enterprise_scale", "counterparty_type", "economic_type", "listed_compary_yes_no", "sup_org_type","actual_controller_type","certificate_type"};
        }else {
            //gdfamc_cus_source客戶來源；sex性別；marry_status婚姻狀況；nation民族；resident_sign居民标志；religion宗教信仰;education学历;degree学位；post职务;occupation职业；identity_verification_results身份核实结果
            str = new String[] {"gdfamc_cus_source","sex","marry_status","nation","resident_sign","religion","education","degree","post","occupation","identity_verification_results"};
        }
        ValueSetValue value = new ValueSetValue();
        for(int i=0;i<str.length;i++){
            value.setValueSetCode(str[i]);
            List<ValueSetValue> valueSetValues = valueSetValueService.selectValueSetValueList(value);
            map.put(str[i], valueSetValues);
        }
        return success(map);
    }

    /**
     * 新增客户基本信息
     */
    @PreAuthorize("@ss.hasPermi('amc:cusmanager:add')")
    @Log(title = "客户基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmcCusBaseInfoB amcCusBaseInfoB)
    {
        return toAjax(amcCusBaseInfoBService.insertAmcCusBaseInfoB(amcCusBaseInfoB));
    }

    /**
     * 修改客户基本信息
     */
    @PreAuthorize("@ss.hasPermi('amc:cusmanager:edit')")
    @Log(title = "客户基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmcCusBaseInfoB amcCusBaseInfoB)
    {
        return toAjax(amcCusBaseInfoBService.updateAmcCusBaseInfoB(amcCusBaseInfoB));
    }

    /**
     * 删除客户基本信息
     */
    @PreAuthorize("@ss.hasPermi('amc:cusmanager:remove')")
    @Log(title = "客户基本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable String[] customerIds)
    {
        return toAjax(amcCusBaseInfoBService.deleteAmcCusBaseInfoBByCustomerIds(customerIds));
    }
}
